<!--
 * @Description: 聚合数据-天气预报
 * @Author: rendc
 * @Date: 2025-11-07 11:48:18
 * @LastEditors: rendc
 * @LastEditTime: 2025-11-07 15:06:56
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>聚合数据-天气预报</title>
</head>
<body>
  聚合数据-天气预报 
</body>
<script>
  // // 创建xhr实例对象
  // var xhr = new XMLHttpRequest();
  // // 初始化新创建的请求 配置请求方法 & URL
  // // get请求的参数拼接 
  // // ?city=1&key=1234xxxx
  // xhr.open("GET","http://apis.juhe.cn/simpleWeather/query?city=1&key=f584618e32c1dfc7e99f0e399b96e1e2");
  // // 设置请求头信息 - 发送格式数据,json
  // xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  // // 发送请求
  // xhr.send();
  // // 获取响应
  // xhr.onreadystatechange = function(){
  //   console.log('🤡 CC - xhr.readyState:', xhr.readyState);
  //   console.log('🤡 CC - xhr.status:', xhr.status);
  //   // 判断请求是否成功
  //   // if (xhr.readyState == 4 && xhr.status == 200) {
  //     // console.log('🤡 CC - xhr.response:', xhr.response);
  //     // console.log('🤡 CC - xhr.responseText:', xhr.responseText);
  //   // }
  // }
    // 模拟请求成功 
    var response = '{"reason":"查询成功!","result":{"city":"北京","realtime":{"temperature":"9","humidity":"84","info":"阵雨","wid":"03","direct":"北风","power":"1级","aqi":"64"},"future":[{"date":"2025-11-07","temperature":"5\/11℃","weather":"小雨","wid":{"day":"07","night":"07"},"direct":"北风转东风"},{"date":"2025-11-08","temperature":"3\/13℃","weather":"多云转晴","wid":{"day":"01","night":"00"},"direct":"西南风转西北风"},{"date":"2025-11-09","temperature":"0\/14℃","weather":"晴","wid":{"day":"00","night":"00"},"direct":"西北风转北风"},{"date":"2025-11-10","temperature":"3\/11℃","weather":"晴转多云","wid":{"day":"00","night":"01"},"direct":"南风转北风"},{"date":"2025-11-11","temperature":"3\/14℃","weather":"晴转多云","wid":{"day":"00","night":"01"},"direct":"南风转北风"}]},"error_code":0}'
    console.log('🤡 CC - response:', response);
    // 渲染到页面上
    // document.createElement("p").innerHTML = response;
    // document.getElementsByTagName("body")[0].innerHTML = response;
    // 序列化 返序列化 
    var obj = JSON.parse(response);
    // console.log('🤡 CC - obj:', obj);
    var city = obj.result.city;
    console.log('🤡 CC - city:', city);
    document.getElementsByTagName("body")[0].innerHTML = city;

</script>
</html>